package br.com.caelum.vraptor.controller;

import javax.inject.Inject;

import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.components.ProfessorSessioned;
import br.com.caelum.vraptor.dao.ProfessorDAO;
import br.com.caelum.vraptor.entidades.Professor;

@Controller
public class LoginprofController {
       
        @Inject
        private Result result;
        @Inject
        private ProfessorDAO professordao;
       
        @Inject
        private ProfessorSessioned professorsessioned;
       
        public LoginprofController() {
                // TODO Auto-generated constructor stub
        }
       
        public void login(String matricula, String senha){
        	Professor prof = professordao.find(matricula, senha);
            professorsessioned.login(prof);
            if(professorsessioned.isLogado()){
                result.redirectTo(IndexController.class).home();;
                }
            else{result.redirectTo(IndexController.class).error();}
        }
               
        public void logar(){
        	
        }
       
        public void logout(){
                professorsessioned.logout();
                result.redirectTo(this).logar();
        }

}

